<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">数据源管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>大数据仓储 &nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">数据源管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">


		<div class="row mbl">
			<div class="col-lg-6">
				<div class="input-group input-group-sm mbs">
					<span class="input-group-btn">
					
						<select id="queryParams" data-toggle="dropdown" class="btn btn-danger dropdown-toggle" style="width :100px;">
		                   	<option value="-1">筛选项&nbsp;<span class="caret"></span></option>
		                    <option value="name">数据源名称</option>
		                    <option value="description">数据源描述</option>
		                    <!-- <option value="sourceType">数据源类型</option>
		                    <option value="url">文件位置</option> -->
                    	</select>
    				</span> <input id="text" type="text" placeholder="请输入关键词..." class="form-control" /><span
						class="input-group-btn"><button type="button"
							data-toggle="dropdown" class="btn btn-success dropdown-toggle" onclick="get()">搜索</button>
					</span>
				</div>
			</div>
			<div class="col-lg-6">
				<div class="tb-group-actions pull-right">
					<span></span> <select id="zhuangTai"
						class="table-group-action-input form-control input-inline input-small input-sm mlm">
						<option value="-1">选择可操作项...</option>
						<option value="1">恢复</option>
						<option value="2">禁用</option>
					</select>&nbsp;
					<button class="btn btn-sm btn-primary" onclick="statusPiLiang()">
						 提交
					</button>
					<button onclick="addEntity('0');" class="btn btn-sm btn-primary">
						 新增
					</button>
				</div>
			</div>
		</div>

		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th width="3%"><input  type="checkbox" class="checkall" /></th>
					<th>序号</th>
					<th>数据源名称</th>
					<th>数据源描述</th>
					
					<th>数据源类型</th>
					<th width="7%">状态</th>
					<th width="13%">可操作</th>
				</tr>
			</thead>
			<tbody id="findDataSource">
			</tbody>
		</table>
		<div id="dataNull" class="panel-body"
				style="height: 90px; line-height: 50px;" align="center">
				<span class='subtitle' style="font-size: 15px;">数据为空!</span>
		</div>
		<div id="page2" style="text-align: center; margin-top: 20px;"></div>
	</div>

	<!--END CONTENT-->
</div>


<?} ?>
<script>
	var curr;
	var id;
	$(function() {
		demo1(curr);
	});
	function get() {
		demo1(curr);
	};
	function getlay() {
		return id;
	};	
			
	function demo1(curr) {
		$.getJSON(
				"./findallDataHandlingSource.do",
				{
					page : curr || 1,
					pageNumber:15,
					queryParams:$("#queryParams").val(),
			        text:$("#text").val(),
				},
				function(res) {
					//此处仅仅是为了演示变化的内容
					var str = "";
					if(res.listsize>0){
						$("#dataNull").hide();
					}else{
						$("#dataNull").show();
					}
					$("#findDataSource").html("");
					for ( var i = 0; i < res.listsize; i++) {
						str += "<tr><td> <input type=\"checkbox\" name=\"check\" value="+res.result[i].id+" />"
								+ "</td><td>"
								+ (i + 1)
								+ "</td><td> <label id=>"
								+ res.result[i].name
								+ "</td><td> <label id=>"
								+ res.result[i].description
								+ "</label></td><td><label >"
								+ res.result[i].sourceType
								+ "</label></td><td><label ><span class=\"label label-sm "+res.result[i].classYangShi+" \">"
								+ res.result[i].status
								+ "</span></label></td><td>"
								+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"del('"
								+ res.result[i].id
								+ "')\">"
								+ "删除"
								+ "</button>&nbsp;"
								+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"addEntity('"
								+ res.result[i].id
								+ "')\">"
								+ "<i class=\"fa fa-edit\"></i>&nbsp;编辑"
								+ "</button>" + "</td></tr>";
					}
					$("#findDataSource").append(str);
					laypage({
						cont : document.getElementById("page2"), //容器。值支持id名、原生dom对象，jquery对象,
						pages : res.pageSize, //总页数
						skip : true, //是否开启跳页
						curr : curr || 1,
						last: res.pageSize,
						skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
						groups : 6,//连续显示分页数
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								demo1(obj.curr);
				                 curr=obj.curr;
							}
						}
					});
				});
	};		
			
	function del(id) {
	layer.alert('是否确认删除！！', {
    	skin: 'layui-layer-molv', //样式类名  自定义样式
   		closeBtn: 1,    // 是否显示关闭按钮
    	anim: 6, //动画类型
    	btn: ['确定','取消'], //按钮
    	icon: 2,    // icon
    	yes:function(){
        	$.ajax({
				type : "post",
				url : "./delDataSource.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					if(data!=null && data!=""){
						demo1();
						layer.msg("删除成功!", {icon: 6});
					}else{
						layer.msg("有关联，不可删除!", {icon: 5});
					}
				},
				error : function(data) {
					layer.msg("连接失败!", {icon: 2});
				}
			});
   		}});
   		/*
		if (confirm("是否确认删除！！"))
		{
			$.ajax({
				type : "post",
				url : "./delDataSource.do",
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					if(data!=null && data!=""){
						demo1();
						layer.msg('删除成功！');
					}else{
						layer.msg('有关联，不可删除！');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
		*/
	};		
			

	function statusPiLiang() {
		if($("#zhuangTai").val()!=-1){
			var check = document.getElementsByName("check");
			var len=check.length;
			var idAll="";
			var count=0;
			for(var i=0;i<len;i++){
				if(check[i].checked){
					count++;
					idAll+=check[i].value+",";
				}
			}
			$("#Xuannum").html("");
			$("#Xuannum").html(count);
			if (confirm("当前已选择"+count+"条！     是否编辑状态！！"))
			{
				$.ajax({
					type : "post",
					url : "./piLiangStatusDataSource.do",
					data : {
						"idAll" : idAll,
						"zhuangtai" : $("#zhuangTai").val()
					},
					dataType : "json",
					success : function(data) {
						$("#Xuannum").html("0");
						layer.msg("编辑成功!", {icon: 6});
						demo1();
					},
					error : function(data) {
						layer.msg("请求失败!", {icon: 2});
					}
				});
			}
		}else{layer.msg("请选择!", {icon: 7});}
	}


	function addEntity(lid) {
		id = lid;
		layer.open({
			type : 2,
			scrollbar : false,
			shadeClose : true,
			move : false,
			title : '数据源管理',
			area : [ '770px', '656px' ],
			fix : false, //不固定
			//maxmin : true,
			content : [ "data-handling-source-addEntity.html", 'no' ],
			btn : [ '保存 ', '关闭' ],
			skin : 'layui-layer-rim', //加上边框
			yes : function(index, layer) {
				iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.Page();
			},
			cancel : function(index) {
			}
		});
	}
</script>